﻿@{
    ViewBag.Title = "ManagerUser";
   // Layout = "~/Views/Shared/_BackstageLayout.cshtml";
}
<link href="~/Scripts/jquery-easyui-1.3.3/themes/default/easyui.css" rel="stylesheet" />
<link href="~/Scripts/jquery-easyui-1.3.3/themes/icon.css" rel="stylesheet" />
<script src="~/Scripts/jquery-easyui-1.3.3/jquery.min.js"></script>
<script src="~/Scripts/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script src="~/Scripts/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>


<body style="margin: 1px;">
    <table id="dg" title="用户管理" class="easyui-datagrid" fitcolumns="true" pagination="true" rownumbers="true" url="/ManagerUser/GetList" fit="true" toolbar="#tb">
        <thead>
            <tr>
                <th field="cb" checkbox="true" align="center"></th>
                <th field="UserID" width="50" align="center">编号</th>
                <th field="RealName" width="100" align="center">真实姓名</th>
                <th field="UserName" width="100" align="center">用户名</th>
                <th field="pwd" width="100" align="center">密码</th>
                <th field="StatusText" width="100" align="center">状态</th>
                
            </tr>
        </thead>
    </table>
    <div id="tb">
        <div>
            <a href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconcls="icon-add" plain="true">添加</a>
            <a href="javascript:openUserModifyDialog()" class="easyui-linkbutton" iconcls="icon-edit" plain="true">修改</a>
            <a href="javascript:deleteUser()" class="easyui-linkbutton" iconcls="icon-remove" plain="true">删除</a>
        </div>
        <div>
            &nbsp;用户名：&nbsp;<input type="text" id="s_userName" name="UserName" size="20" onkeydown="if(event.keyCode==13) searchUser()" />
            <a href="javascript:searchUser()" class="easyui-linkbutton" iconcls="icon-search" plain="true">搜索</a>
        </div>
    </div>

    <div id="dlg" class="easyui-dialog" style="width: 570px; height: 300px; padding: 10px 20px"
        closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post">
            <table cellspacing="8px">
                <tr>
                   <td>用户名：</td>
                    <td>
                        <input type="text" id="userName" name="UserName" class="easyui-validatebox" required="true" /></td>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>密码：</td>
                    <td>
                        <input type="text" id="password" name="pwd" class="easyui-validatebox" required="true" /></td>
                </tr>
                <tr>
                     <td>真实姓名：</td>
                    <td>
                        <input type="text" id="trueName" name="RealName" class="easyui-validatebox" required="true" /></td>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>状态：</td>
                    <td>
                        <select class="easyui-combobox" id="sta" name="Status" style="width: 154px;" editable="false" panelHeight="auto">
	 						<option value="">请选择</option>
	 						<option value="1">正常</option>
	 						<option value="2">异常</option>
	 					</select>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <div id="dlg-buttons">
        <a href="javascript:saveUser()" class="easyui-linkbutton" iconcls="icon-ok">保存</a>
        <a href="javascript:closeUserDialog()" class="easyui-linkbutton" iconcls="icon-cancel">关闭</a>
    </div>
</body>

<script type="text/javascript">

    var url;

    function searchUser() {
        alert($("#s_userName").val());
        $("#dg").datagrid('load', {
            "/ManagerUser/GetList": $("#s_userName").val()
        });
    }

    //删除
    function deleteUser() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要删除的数据！");
            return;
        }
        var strIds = [];
        for (var i = 0; i < selectedRows.length; i++) {
            strIds.push(selectedRows[i].UserID);
        }
        var ids = strIds.join(",");
        $.messager.confirm("系统提示", "您确认要删除这<font color=red>" + selectedRows.length + "</font>条数据吗？", function (r) {
            if (r) {
                $.post("/ManagerUser/DeleteUser", { ids: ids }, function (result) {
                    if (result) {
                        $.messager.alert("系统提示", "数据已成功删除！");
                        $("#dg").datagrid("reload");
                    } else {
                        $.messager.alert("系统提示", "数据删除失败！");
                    }
                }, "json");
            }
        });

    }

   //弹窗
    function openUserAddDialog() {
        $("#dlg").dialog("open").dialog("setTitle", "添加用户信息");
        url = "/ManagerUser/AddUser";
    }

    //保存
    function saveUser() {
        $("#fm").form("submit", {
            url: url,
            onSubmit: function () {
                if ($("#sta").combobox("getValue") == "") {
                    $.messager.alert("系统提示", "请选择状态");
                    return false;
                }
                return $(this).form("validate");
            },
            success: function (result) {
                if (result) {
                    $.messager.alert("系统提示", "保存成功");
                    resetValue();
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                } else {
                    $.messager.alert("系统提示", "保存失败");
                    return;
                }
            }
        });
    }

    //修改
    function openUserModifyDialog() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要编辑的数据！");
            return;
        }
        var row = selectedRows[0];
        $("#dlg").dialog("open").dialog("setTitle", "编辑用户信息");
        $("#userName").val(row.UserName);
        $("#password").val(row.pwd);
        $("#trueName").val(row.RealName);
        $("#sta").combobox("setValue", row.Status);
        url = "/ManagerUser/Update?id=" + row.UserID;
    }

    function resetValue() {
        $("#userName").val("");
        $("#password").val("");
        $("#trueName").val("");
        $("#sta").combobox("setValue", "");
    }

    //关闭
    function closeUserDialog() {
        $("#dlg").dialog("close");
        resetValue();
    }
</script>

